﻿<cfsilent>
	<cfscript>
		
		propAdvice = getProperty("serviceFactory").getBean("studentPropertyAdvice");
	
		event.setArg("pageTitle", "学位管理 - 学位资格审核 - 专业总览");
		
		subjectId = event.getArg("SBJ");
		grade = event.getArg("GRD");

		/* 可用的学位审核条件 */
		enableTemplate = "CBD, CPD, GPD";
		
		/* 读取专业信息 */
		sql = "SELECT sbj_name FROM t_subject WHERE sbj_id = :subjectId ";
		
		queryObj = new Query( datasource=application.dnsSlave );
		queryObj.addParam( name="subjectId", value=subjectId, cfsqltype="cf_sql_varchar" );

		rs_subject = queryObj.execute( sql=sql ).getResult();
		
		/* 读取指定专业、年级待审查学位信息 */
		sql = "SELECT 
					a.is_passed, a.comp_passed, a.review_passed, 
					b.stu_id, b.stu_name, 
					d.cls_name, 
					c.credit_grad, c.credit_grad_pt, c.credit_grad_avgpt  
					FROM t_degree_review a 
					INNER JOIN t_student b ON b.stu_id = a.stu_id 
					INNER JOIN t_student_profile c ON c.stu_id = a.stu_id 
					INNER JOIN t_class d ON d.cls_id = b.cls_id 
					WHERE 
						d.grade = :grade 
						AND 
						d.sbj_id = :subjectId 
					ORDER BY 
						b.stu_id ";
		
		queryObj = new Query( datasource=application.dnsSlave );
		queryObj.addParam( name="grade", value=grade, cfsqltype="cf_sql_char" );
		queryObj.addParam( name="subjectId", value=subjectId, cfsqltype="cf_sql_varchar" );

		rs_summary = queryObj.execute( sql=sql ).getResult();


		/* 读取学位条件 */
		sql = "SELECT 
				gdc, gdc_descript, gdc_params 
				FROM t_grad_condition 
				WHERE gdc in ( :enableTemplate )
				ORDER BY gdc";

		queryObj = new Query( datasource=application.dnsSlave );
		queryObj.addParam( name="enableTemplate", value=enableTemplate, cfsqltype="cf_sql_char", list=true, separator=", " );

		rs_condition = queryObj.execute( sql=sql ).getResult();
		
		
		/* 培养方案学分要求 */
		sql = "SELECT 
					credit, credit_required, credit_optional, 
					credit_relish, grade, period, period_required, 
					period_optional 
				FROM t_condition 
				WHERE
					grade = :grade 
					AND 
					sbj_id = :subjectId"; 
		
		queryObj.addParam( name="grade", value=grade, cfsqltype="cf_sql_char" );
		queryObj.addParam( name="subjectId", value=subjectId, cfsqltype="cf_sql_varchar" );

		rs_schema = queryObj.execute( sql=sql ).getResult();
		
		/* 审核参数默认值 */
		TPLP = structNew();
		
		for ( TPL in listToArray(enableTemplate, ", ") ) {
			structInsert( TPLP, TPL, 0 );
		}

		/* 搜索已经毕业学生 */
		keyword = event.getArg("Keywords");
		
		rs_student = queryNew("stu_id, stu_name, cls_name, student_prop");
		
		if ( len(keyword) ) {
			
			sql = "SELECT 
						 a.stu_id, a.stu_name, 
						 b.cls_name, 
						 d.student_prop 
					FROM 
						 t_student a 
						 INNER JOIN t_class b ON b.cls_id = a.cls_id 
						 INNER JOIN t_degree_review c ON c.stu_id = a.stu_id 
						 INNER JOIN t_student_status d ON d.stu_id = a.stu_id 
					WHERE 
						 b.grade = :grade 
						 AND 
						 b.sbj_id = :subjectId  
						 AND (
						 	a.stu_id LIKE :condition 
						 	OR 
						 	a.stu_name LIKE :condition 
							) 
					ORDER BY 
						 a.stu_name ";
					
			queryObj = new Query( datasource=application.dnsSlave, maxRows=60 ) ;
			queryObj.addParam( name="condition", value=keyword&"%" , cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="grade", value=grade, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="subjectId", value=subjectId, cfsqltype="cf_sql_varchar" );
			
			rs_student = queryObj.execute( sql=sql ).getResult();
			
			
		}
		
		currentTab = event.getArg("TabID", "labDetail");
		
		passArgs = structNew();
		structInsert( passArgs, "SBJ", subjectId, true );
		structInsert( passArgs, "GRD", grade, true );

	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
				<a class="uiButton" href="<cfoutput>#buildURL('gradDegreeReview')#</cfoutput>"><i class="mrs img btnPublish"></i><span class="uiButtonText">授予学位资格审核</span></a>
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 subject"></i> <cfoutput>#rs_subject.sbj_name#</cfoutput> 专业 - <cfoutput>#grade#</cfoutput> 级毕业生
				</h2>
			</div>
		</div>
	</div>
</div>

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="summary">
				<div class="UItab">
					<div class="tabLables">
						<span <cfif currentTab eq "labDetail">class="active"</cfif> id="labDetail" tabTarget="Detail">学分修读情况一览表</span>
						<span <cfif currentTab eq "labReview">class="active"</cfif> id="labReview" tabTarget="Review">学位资格审核</span>
						<span <cfif currentTab eq "labSearch">class="active"</cfif> id="labSearch" tabTarget="Search">搜索毕业生</span>
					</div>
				</div>
				<script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					$(document).ready(function() {
						
						/* init Tab */
						$("div.tabContent").hide();
						$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
						
						$("div.tabLables > span").click(function(){
							var $targetID = $(this).attr("tabTarget");
							
							$("div.tabLables span").removeClass("active");
							$(this).addClass("active");
							
							$("div.tabContent").not('[id="' + $targetID + '"]').hide();
							$("div.tabContent#" + $targetID).show();
						});
						
					});
					// -->
					//]]>
				</script>
				
				<div id="Detail" class="tabContent">
					
					<div class="noticeBlock">
						<div class="operation">
							<a class="uiButton uiButtonSpecial" href="<cfoutput>#buildURL('gradDegreeBySubjectDownloadExcel', passArgs)#</cfoutput>"><i class="mrs img btnDownload"></i><span class="uiButtonText">下载学位审查结果汇总表</span></a>
						</div>
						<h3>学分修读情况汇总</h3>
						<p><span class="img icon16x16 message"></span>该专业已经毕业学生 <em><cfoutput>#rs_summary.recordCount#</cfoutput></em> 名, 下列是该专业毕业生学位课学分修读情况汇总 </p>
						<hr/>
					</div>

					<cfset row = 0 />
					<table class="UIEditable">
						<thead>
							<tr>
								<td width="25"></td>
								<td>班级</td>
								<td width="90">学号</td>
								<td>姓名</td>
								
								<td width="50">总学分</td>
								<td width="45">绩点</td>
								<td width="50">平均绩点</td>
								
								<td width="28" align="center">通过</td>
								<td width="28" align="center">机审</td>
								<td width="28" align="center">复审</td>

								<td width="18"></td>
							</tr>
						</thead>
						
						<tbody>
							<cfloop query="rs_summary">
									
								<cfset row++ />
								<cfset structInsert( passArgs, "STU", rs_summary.stu_id, true ) />
								
								<tr class="editRows">
									<td class="index"><cfoutput>#row#</cfoutput></td>
									<td><cfoutput>#rs_summary.cls_name#</cfoutput></td>
									<td><span class="numeric"><cfoutput>#rs_summary.stu_id#</cfoutput></span></td>
									<td><cfoutput>#rs_summary.stu_name#</cfoutput></td>

									<td><cfif rs_summary.credit_grad gt 0><span class="numeric greenCell"><cfoutput>#numberFormat( rs_summary.credit_grad, "_.__" )#</cfoutput></span></cfif></td>
									<td><cfif rs_summary.credit_grad_pt gt 0><span class="numeric orangeCell"><cfoutput>#numberFormat( rs_summary.credit_grad_pt, "_.__" )#</cfoutput></span></cfif></td>
									<td><cfif rs_summary.credit_grad_avgpt gt 0><span class="numeric blueCell"><cfoutput>#numberFormat( rs_summary.credit_grad_avgpt, "_.__" )#</cfoutput></span></cfif></td>
									
									<td align="center"><span class="stat grad<cfoutput>#rs_summary.is_passed#</cfoutput>"></span></td>
									<td align="center"><span class="stat grad<cfoutput>#rs_summary.comp_passed#</cfoutput>"></span></td>
									<td align="center"><span class="stat grad<cfoutput>#rs_summary.review_passed#</cfoutput>"></span></td>

									<td><a title="人工复审授予学位资格" href="<cfoutput>#buildURL('gradDegreeProfileView', passArgs)#</cfoutput>" class="stat sign"></a></td>
								</tr>
								
							</cfloop>
							
							<!--- 移除额外参数 --->
							<cfset structDelete( passArgs, "STU" ) />
							
						</tbody>
					</table>

				</div>

				<div id="Review" class="tabContent">
				
					<div class="noticeBlock">
						<h3>授予学位资格自动审核</h3>
						<p><span class="img icon16x16 message"></span>该专业毕业生 <em><cfoutput>#rs_summary.recordCount#</cfoutput></em> 名, 请根据实际情况设置该专业授予学位需满足的审查条件 </p>
						<hr/>
					</div>
					
					<form id="formCondition" class="formWrapper " method="post" action="<cfoutput>#buildURL('gradStudentBySubject', passArgs)#</cfoutput>">
						
						<div class="label">
							<b>学位审核条件</b>
							<div class="secondRow">
								<table>
									<cfloop query="rs_condition">
										<tr>
											<td><input name="TPL" type="checkbox" class="typeCheckbox" verification="group" value="<cfoutput>#rs_condition.gdc#</cfoutput>" /></td>
											<td><cfoutput>#rs_condition.gdc_descript#</cfoutput></td>
											<td>
												<cfif rs_condition.gdc_params neq "NOPE">
													<input id="TPLP-<cfoutput>#rs_condition.gdc#</cfoutput>" type="text" class="typeSmallInt" verification="double" value="<cfoutput>#TPLP[rs_condition.gdc]#</cfoutput>" />
												</cfif>
											</td>
										</tr>
									</cfloop>
								</table>
							</div>
						</div>
						
						<hr/>
							
						<div class="lable">
							<input id="startReview" class="button" type="button" value="自动审核" />
						</div>
						
					</form>
					
					<!---<div id="out"></div>--->
					
					<div id="processOutput" class="hidden_elem">
						
						<div class="UIProgressbar">
							<span class="progressBar" id="pb1">0%</span>
							<p id="output">处理队列初始化</p>
							<p id="info"></p>
						</div>
						
					</div>
					
					<div id="processComplete" class="clearfix hidden_elem">
						<ul class="UIDashBoard">
							<li class="col2">
								<div class="board hasPic">
									<a href="<cfoutput>#buildURL("gradDegreeBySubject", passArgs)#</cfoutput>">
										<div class="pic">
											<span class="icon64x64 studentReview"></span>
										</div>
										<div class="content">
											<h3 class="pass"><span id="studentPassed">0</span><span class="unitALL">/ <cfoutput>#rs_summary.recordCount#</cfoutput></span></h3>
											<h5>自动审核完成</h5>
											<p class="describ">根据您设置的条件, 系统已完成自动审核, 请点这里查看机审结果</p>
										</div>
									</a>
								</div>
							</li>
						</ul>
					</div>

					<script language="javascript" type="text/javascript">
						//<![CDATA[
						<!--
						$(document).ready(function() {

							var studentArray = [<cfloop query="rs_summary">'<cfoutput>#rs_summary.stu_id#</cfoutput>'<cfif rs_summary.currentRow LT rs_summary.recordCount>,</cfif></cfloop>];

							$("#startReview").click(function(){
								
								var formCheck = processVerfiyForm("formCondition");

								if ( formCheck ) {
									
									/* 隐藏表单 */
									$("#formCondition").addClass("hidden_elem");
									
									/* 显示处理进度 */
									$("#processOutput").removeClass("hidden_elem");
									
									
									/* init Progress */
									$("#pb1").progressBar({
															boxImage		: '<cfoutput>#getProperty('cdnServer')#</cfoutput><cfoutput>#getContextRoot()#</cfoutput>/acadmicRes/assets/widget/progressbar/images/progressbar.gif',
															barImage		: {
																				0:  '<cfoutput>#getProperty('cdnServer')#</cfoutput><cfoutput>#getContextRoot()#</cfoutput>/acadmicRes/assets/widget/progressbar/images/progressbg_red.gif',
																				30: '<cfoutput>#getProperty('cdnServer')#</cfoutput><cfoutput>#getContextRoot()#</cfoutput>/acadmicRes/assets/widget/progressbar/images/progressbg_orange.gif',
																				70: '<cfoutput>#getProperty('cdnServer')#</cfoutput><cfoutput>#getContextRoot()#</cfoutput>/acadmicRes/assets/widget/progressbar/images/progressbg_green.gif'
																				}
															});
									
									
									/* 显示阻挡信息 */
									$.blockUI({ 
												message: '正在自动审核学位课修读情况...请耐心等待',
												css: { 
														'width': '16%',
														'left': '42%',
														'border': 'none', 
														'padding': '15px 5px', 
														'backgroundColor': '#F60', 
														'border-radius': '4px', 
														'opacity': .9, 
														'color': '#fff',
														'cursor': null
														},
												overlayCSS: {
														'backgroundColor': '#aaa', 
														'opacity': .1 ,
														'cursor': null
														}
												});	

									processStudent(0);
								}
								
							});
							
							function processStudent(current) {
								
								var studentId = studentArray[current];
								
								var templateIds = [];
								
								$(":checkbox:checked[name='TPL']").each(function(index, element) {
									templateIds.push( $(this).val() );
								});

								/* 调用 ajax 方式进行自动毕业审核 */
								$.post(
										"<cfoutput>#buildURL('apiDegreeComputerReview')#</cfoutput>", 
										{
											'STU': studentId,
											'TPL': templateIds.join(","), 
											<cfloop query="rs_condition">'TPLP-<cfoutput>#rs_condition.gdc#</cfoutput>': $("#TPLP-<cfoutput>#rs_condition.gdc#</cfoutput>").val(),
											</cfloop>
											'seed': (new Date()).getTime()
										}, 
										function(data) {
											
											//$("#out").html(data);
											response = $.parseJSON(data);
											
											$("#output").html( "PROC-" + current + "/" + studentArray.length + ". " + response.operation);
											
											/* 刷新已审核通过学生计数 */
											if ( response.passed ) {
												var studentPassed = parseInt( $("#studentPassed").text() ) + 1;
												$("#studentPassed").text( studentPassed );
											}
											
											/* fresh progress bar */
											var percentage = Math.floor(100 * parseInt(current + 1) / parseInt(studentArray.length));
											
											$("#pb1").progressBar(
																	percentage,
																	{
																		boxImage : '<cfoutput>#getProperty('cdnServer')#</cfoutput><cfoutput>#getContextRoot()#</cfoutput>/acadmicRes/assets/widget/progressbar/images/progressbar.gif',
																		barImage : {
																			0:  '<cfoutput>#getProperty('cdnServer')#</cfoutput><cfoutput>#getContextRoot()#</cfoutput>/acadmicRes/assets/widget/progressbar/images/progressbg_red.gif',
																			30: '<cfoutput>#getProperty('cdnServer')#</cfoutput><cfoutput>#getContextRoot()#</cfoutput>/acadmicRes/assets/widget/progressbar/images/progressbg_orange.gif',
																			70: '<cfoutput>#getProperty('cdnServer')#</cfoutput><cfoutput>#getContextRoot()#</cfoutput>/acadmicRes/assets/widget/progressbar/images/progressbg_green.gif'
																		},
																		callback: function(running){
																	
																			if (running.running_value == running.value) {
																	
																				current++;
											
																				if ( current < studentArray.length) {
																					processStudent(current);
																				}
																				else {
																				
																					$("#output").text("完成");
																					$("#processComplete").removeClass("hidden_elem");
																					$("#processOutput").addClass("hidden_elem");
																					
																					/* 取消阻挡 */
																					$.unblockUI();
																				}
																			}
																		}
																
																	});
											
									});
								
							}
								
						});
						
						// -->
						//]]>
					</script>
				
				</div>

				<div id="Search" class="tabContent">
					
					<form id="formSearch" onSubmit="javascript:return processVerfiyForm('formSearch');" class="formWrapper Transparent" method="post" action="<cfoutput>#buildURL('gradDegreeBySubject')#</cfoutput>">
						
						<input type="hidden" name="TabID" value="labSearch" />
						<input type="hidden" name="GRD" value="<cfoutput>#grade#</cfoutput>" />
						<input type="hidden" name="SBJ" value="<cfoutput>#subjectId#</cfoutput>" />
						
						<div class="label">
							<b>学号或姓名</b>
							<input name="Keywords" id="Keywords" type="text" class="typeText" verification="required" maxlength="128" value="<cfoutput>#event.getArg('Keywords')#</cfoutput>" />
						</div>
						<hr/>
						<div class="lable">
							<input class="button1" type="submit" value="搜索" />
						</div>
					</form>
					
					<cfif rs_student.recordCount>

						<div class="clearfix">
							<div class="UICardTable">
                                <cfloop query="rs_student" >
									
									<cfset structInsert( passArgs, "STU", rs_student.stu_id, true ) />
									<cfset propAdvice.parseProperty( rs_student.student_prop ) />
									
									<dl <cfif not propAdvice.getInSchool()>class="disabled"</cfif>>
										<dt>
											<a href="<cfoutput>#buildURL('gradDegreeProfileView', passArgs)#</cfoutput>">
												<em class="people"><!--imgholder--></em>
												<dd>
													<h3><cfoutput>#rs_student.stu_name#</cfoutput> - <cfoutput>#rs_student.cls_name#</cfoutput></h3>
													<p><cfoutput>#rs_student.stu_id#</cfoutput></p>
												</dd>
											</a>
										</dt>
									</dl>
								</cfloop>
								<!--- 移除额外参数 --->
								<cfset structDelete( passArgs, "STU" ) />								
							</div>
						</div>
					
					</cfif>
					
				</div>
				
			</div>
		</li>
	</ul>
</div>